<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 因此表更新频繁，所以此表理论上只记录数值类型数据
        Schema::create('user_extend', function (Blueprint $table) {
            $table->engine  = 'InnoDB';
            $table->comment('用户扩展表');

            $table->increments('id');
            $table->integer('create_time')->comment('创建时间')->unsigned()->default(0);
            $table->integer('user_id')->comment('账号id')->unsigned()->default(0);
            $table->integer('update_time')->comment('最后更新时间')->unsigned()->default(0);

            $table->double('total_pay_amount')->comment('总充值金额')->unsigned()->default(0);
            $table->double('total_pay_num')->comment('总充值次数')->unsigned()->default(0);

            $table->double('today_pay_amount')->comment('当天充值金额')->unsigned()->default(0);
            $table->integer('last_pay_time')->comment('最后充值时间')->unsigned()->default(0);

            $table->integer('first_pay_orderid')->comment('首次充值订单id')->unsigned()->default(0);
            $table->integer('first_pay_time')->comment('首次充值时间')->unsigned()->default(0);
            $table->double('first_pay_amount')->comment('首次充值金额')->unsigned()->default(0);

            $table->integer('last_login_time')->comment('最后登录时间')->unsigned()->default(0);

            $table->unique('user_id');
            $table->index('update_time');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_extend');
    }
};
